Part 1: Interactive tmap of oil spill locations across California

#map these together

tmap_mode(mode = "view")

tm_shape(counties)+
  tm_borders("darkolivegreen3")+
  tm_shape(oil_spill)+
  tm_dots(alpha = 0.3, col = "darkgoldenrod2", border.col = "darkgoldenrod2", border.alpha = 1)

Chloropath map

# filter out marine oil spills
oil_spill %>% 
  filter(INLANDMARI == "Inland")
## Simple feature collection with 2025 features and 13 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -13828120 ymin: 3835264 xmax: -12757590 ymax: 5156169
## projected CRS:  WGS 84 / Pseudo-Mercator
## # A tibble: 2,025 x 14
##    OBJECTID DFGCONTROL OESNUMBER DATEOFINCI TIMEOFINCI INLANDMARI SPECIFICLO
##  *    <int> <chr>      <chr>     <date>     <chr>      <chr>      <chr>     
##  1        2 08FG0798   08-1391   2008-02-17 0632       Inland     Fresh Wat…
##  2        3 08FG3355   08-7520   2008-10-16 1737       Inland     Fresh Wat…
##  3        4 08FG3531   08-7979   2008-10-30 1700       Inland     Fresh Wat…
##  4        5 08FG2139   08-4440   2008-06-22 0449       Inland     Fresh Wat…
##  5        6 08FG3543   08-8018   2008-11-02 0830       Inland     Fresh Wat…
##  6        7 08FG3749   08-8501   2008-11-27 1210       Inland     Fresh Wat…
##  7        8 08FG4063   08-9175   2008-12-27 1230       Inland     Fresh Wat…
##  8        9 08FG0608   08-1011   2008-02-01 1930       Inland     Fresh Wat…
##  9       10 08FG2858   08-6328   2008-08-29 1200       Inland     Fresh Wat…
## 10       11 08FG0530   08-0870   2008-01-28 1230       Inland     Fresh Wat…
## # … with 2,015 more rows, and 7 more variables: WATER <chr>, WATERWAY <chr>,
## #   LOCALECITY <chr>, LOCALECOUN <chr>, LATITUDE <dbl>, LONGITUDE <dbl>,
## #   geometry <POINT [m]>
#join the oil spill data with the counties data
oil_counties_join <- counties %>% 
  st_join(oil_spill)

# count the number of oil spills in each county 
chloro_oil <- oil_counties_join%>% 
  count(county_name)

# plot these with ggplot 
ggplot(data = chloro_oil) +
  geom_sf(aes(fill = n), color = "white", size = 0.1) +
  scale_fill_gradientn(colors = c("gold","darkorange","firebrick")) +
  theme_void() +
  labs(fill = "Number of Oil Spills", 
       title = "Number of Oil Spills by County in 2008")